Macros
A macro is a restricted PHP code dedicated to execute the design's complex tasks. For this reason, Div assures that the PHP code will be not intrusive or insecure.
Syntax
<?
// ... some PHP code here ...
?>
Example
index.php
<?php
include 'div.php';
class page extends div{
public function upper($str){
return strtoupper($str);
}
}
echo new page('index.tpl', [
'products' => ['Banana', 'Potato']
]);
index.tpl
{= text: "hello" =}
{$text}
<?
// upper() is a method of current class
$text = upper($text);
?>
{$text}
Products:
<?
$i = 0;
foreach($products as $product) {
$i++;
echo "$i - $product\n";
}
?>
They are {$i} products
Output
hello
HELLO
Products:
1 - Banana
2 - Potato
They are 2 products